package com.yql.controller;

import com.yql.entity.User;
import com.yql.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class UserController {
    @Autowired
    UserService userService;
    @GetMapping("login")
    public String login(){
        return "login";
    }

    @PostMapping("login")
    public String login(User user, HttpSession session){
        User user1 = userService.login(user);
        if(null!=user1){
            session.setAttribute("user",user1);
            return "redirect:tree";
        }else{
            return "login";
        }
    }
}
